#include <iostream>
using namespace std;

/*
	1 cin >> endl;
	2 if-else(<=3)  switch-case(>=3)
	3 bool  true(1) false(0)   _Bool
	4 除数为0的判断      浮点数的判0    int==0

	异常:	程序执行过程中，发生类某种错误(java   空指针异常)
		C 在错误出现的地方马上处理
		C++ 在错误的地方抛出异常，在需要捕获的地方捕获异常处理
			throw 			抛出异常
			try				异常检测
			catch			接收并处理异常
		
*/

double getResult(double numberA, double numberB, char sign)
{
	double result = 0.0;
	//2 根据运算符计算出运算的结果
	switch(sign){
		case '+':
			result = numberA + numberB;	
			break;
		case '-':
			result = numberA - numberB;	
			break;
		case '*':
			result = numberA * numberB;	
			break;
		case '/':
			if(numberB > -0.000001 && numberB < 0.000001)	//为0
			{
				//抛出异常:一但发生异常会跳出try语句块
				throw string("除数不能为0!");
			}
			result = numberA / numberB;	
			break;
		defualt:
			break;
	}
	return result;
}
int main(int argc, char *argv[])
{
	//1 定义变量
	double numberA = 0.0;
	double numberB = 0.0;
	char sign = '\0';

	//double r = numberAsignnumberB;
	//1 输入
	cout << "请输入表达式: ";
	cin >> numberA >> sign >> numberB;

	bool flag = true;			//1 正确运算  0 运算错误
	double result = 0.0;
	try{
		result = getResult(numberA, numberB, sign);
	}catch(const string& err){
		cerr << "error: " << err;
		flag = false;
	}

	if(flag){
		cout << numberA << " " << sign << " " << numberB << " = " << result << endl;
	}
	return 0;
}
